home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / filbx2 / filebox.frm < prev    next >
Text File  |  1995-05-08  |  11KB  |  452 lines

  1. VERSION 2.00
  2. Begin Form FileBox 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Open File"
  5.    ClientHeight    =   2775
  6.    ClientLeft      =   3420
  7.    ClientTop       =   945
  8.    ClientWidth     =   5565
  9.    Height          =   3180
  10.    Icon            =   FILEBOX.FRX:0000
  11.    Left            =   3360
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   2775
  17.    ScaleWidth      =   5565
  18.    Top             =   600
  19.    Width           =   5685
  20.    Begin DirListBox Dir1 
  21.       Height          =   280
  22.       Left            =   3930
  23.       TabIndex        =   9
  24.       Top             =   1320
  25.       Visible         =   0   'False
  26.       Width           =   1470
  27.    End
  28.    Begin ListBox List1 
  29.       Height          =   1395
  30.       Left            =   2040
  31.       TabIndex        =   5
  32.       Top             =   1180
  33.       Width           =   1815
  34.    End
  35.    Begin DriveListBox Drive1 
  36.       Height          =   360
  37.       Left            =   3915
  38.       TabIndex        =   8
  39.       Top             =   980
  40.       Visible         =   0   'False
  41.       Width           =   1500
  42.    End
  43.    Begin FileListBox File1 
  44.       Height          =   1785
  45.       Left            =   210
  46.       TabIndex        =   3
  47.       Top             =   820
  48.       Width           =   1695
  49.    End
  50.    Begin CommandButton Cancel 
  51.       Cancel          =   -1  'True
  52.       Caption         =   "Cancel"
  53.       Height          =   360
  54.       Left            =   4335
  55.       TabIndex        =   7
  56.       Top             =   560
  57.       Width           =   1095
  58.    End
  59.    Begin CommandButton OK 
  60.       Caption         =   "OK"
  61.       Default         =   -1  'True
  62.       Height          =   360
  63.       Left            =   4335
  64.       TabIndex        =   6
  65.       Top             =   120
  66.       Width           =   1095
  67.    End
  68.    Begin TextBox Text1 
  69.       Height          =   300
  70.       Left            =   1320
  71.       TabIndex        =   1
  72.       Text            =   "*.*"
  73.       Top             =   140
  74.       Width           =   2760
  75.    End
  76.    Begin Label Label4 
  77.       Caption         =   "&Directories:"
  78.       Height          =   260
  79.       Left            =   2070
  80.       TabIndex        =   4
  81.       Top             =   900
  82.       Width           =   1530
  83.    End
  84.    Begin Label Label1 
  85.       Height          =   260
  86.       Left            =   1950
  87.       TabIndex        =   10
  88.       Top             =   500
  89.       Width           =   2160
  90.    End
  91.    Begin Label Label3 
  92.       Caption         =   "&Files:"
  93.       Height          =   240
  94.       Left            =   255
  95.       TabIndex        =   2
  96.       Top             =   480
  97.       Width           =   825
  98.    End
  99.    Begin Label Label2 
  100.       Caption         =   "File &Name:"
  101.       Height          =   260
  102.       Left            =   285
  103.       TabIndex        =   0
  104.       Top             =   140
  105.       Width           =   975
  106.    End
  107. End
  108. '                               Filebox/Filebox2 by
  109. '                                   Thomas Kiehl
  110. '                                   P.O. Box 693
  111. '                         Indian Rocks Beach, FL  34635
  112. '
  113. '                                  CIS: 73215,427
  114. '
  115. '
  116. 'This File Open Dialog Box Form and associated modules and forms are hereby released
  117. 'to the public domain to be used as seen fit by those who may use it, provided that
  118. 'such user understands that the author expresses no warranty, promise or claim of
  119. 'liability for its use, consequental use and/or damages to hardware, software or data.
  120.  
  121.  
  122.  
  123. DefInt A-Z
  124.  
  125. ' FILEBOX declarations and constants
  126.  
  127.  
  128. Dim LastChanged
  129. Dim LastPattern As String
  130. Dim CurrDir As String
  131.  
  132. Const ASCII_ENTER = 13
  133. Const WM_USER = &H400
  134. Const LB_RESETCONTENT = WM_USER + 5
  135.  
  136. Const TEXT_CHANGED = 0
  137. Const FILE_CHANGED = 1
  138. Const DIR_CHANGED = 2
  139.  
  140. Declare Function SendMessage% Lib "user" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam&)
  141. Declare Function GetFocus% Lib "user" ()
  142. Declare Function PutFocus% Lib "user" Alias "SetFocus" (ByVal hWnd%)
  143.  
  144.  
  145. Sub Cancel_Click ()
  146.     Unload Filebox
  147. End Sub
  148.  
  149. Sub ClearListBox (Ctrl As Control)
  150.  
  151.   If Ctrl.Visible Then
  152.     hWndOld = GetFocus()
  153.     list1.SetFocus
  154.     x = SendMessage(GetFocus(), LB_RESETCONTENT, 0, 0)
  155.     x = PutFocus(hWndOld)
  156.   End If
  157.  
  158. End Sub
  159.  
  160. Sub Command1_Click ()
  161.     Unload Filebox
  162. End Sub
  163.  
  164. Sub Dir1_change ()
  165.   
  166.   ChDir (Dir1.path)
  167.   file1.path = Dir1.path
  168.   Label1.Caption = file1.path
  169.   List1_Update
  170.  
  171. End Sub
  172.  
  173. Sub Drive1_Change ()
  174.  
  175.  On Error Resume Next
  176.  
  177.  Dir1.path = CurDir$(drive1.drive)
  178.  If Err Then                'chances of an error getting here are slim
  179.   MsgBox Error$
  180.   drive1.drive = Dir1.path
  181.  End If
  182.  
  183.  List1_Update
  184.  
  185. End Sub
  186.  
  187. Sub File1_Click ()
  188.     
  189.     LastChanged = FILE_CHANGED
  190.     
  191.     If file1.Listindex >= 0 Then    'zero based filename index
  192.         text1.text = file1.filename
  193.     End If
  194.     If text1.text = "" Then
  195.         OK.enabled = False
  196.     Else
  197.         OK.enabled = True
  198.     End If
  199.  
  200. End Sub
  201.  
  202. Sub File1_DblClick ()
  203.     
  204.     LastChanged = FILE_CHANGED
  205.     OK_Click
  206.  
  207. End Sub
  208.  
  209. Sub File1_KeyPress (KeyAscii As Integer)
  210.     
  211.     LastChanged = FILE_CHANGED
  212.     If text1.text = "" Then
  213.         OK.enabled = False
  214.     Else
  215.         OK.enabled = True
  216.     End If
  217.  
  218. End Sub
  219.  
  220. Sub Form_Load ()
  221.  
  222.   Filebox.top = 1240
  223.   Filebox.left = 2592
  224.   Filebox.height = 3240
  225.   Filebox.width = 5640
  226.  
  227.   LastPattern = "*.*"
  228.   file1.Pattern = LastPattern
  229.   List1_Update
  230.   Label1.Caption = file1.path
  231.   text1.selstart = 0
  232.   text1.sellength = Len(text1.text)
  233.   OK.enabled = True
  234.   LastChanged = TEXT_CHANGED
  235.  
  236. End Sub
  237.  
  238. Sub List1_Click ()
  239.  
  240.   Dim startpos As Integer
  241.   
  242.   LastChanged = DIR_CHANGED
  243.   OK.enabled = True
  244.   
  245.   If list1.text = "[..]" Then            ' Change to the parent directory
  246.     text1.text = "..\" + file1.Pattern
  247.   Else
  248.     If Left$(list1.text, 2) = "[-" Then   ' This is a drive spec
  249.         text1.text = Mid$(list1.text, 3, 1) + ":" + file1.Pattern
  250.     Else ' This is a subdirectory of the current directory
  251.         startpos = Len(CurrDir) + 2
  252.         If list1.List(0) = "[..]" Then
  253.             text1.text = Mid$(Dir1.List((list1.Listindex) - 1), startpos) + "\" + file1.Pattern
  254.         Else
  255.             text1.text = Mid$(Dir1.List(list1.Listindex), startpos - 1) + "\" + file1.Pattern
  256.         End If
  257.     End If
  258.   End If
  259.  
  260. End Sub
  261.  
  262. Sub List1_Dblclick ()
  263.   
  264.   LastChanged = DIR_CHANGED
  265.   If list1.text = "[..]" Then                     'the parent directory
  266.     Dir1.path = Dir1.List(-2)
  267.     Dir1_change
  268.   Else
  269.     If Left$(list1.text, 2) = "[-" Then           'this is a drive spec
  270.       On Error GoTo list1_error
  271.       Dummy$ = Dir$(Mid$(list1.text, 3, 1) + ":") 'error if door is open
  272.                                                   'error has been trapped out
  273.       drive1.drive = Mid$(list1.text, 3, 1) + ":" 'error if door is open (we did check it)
  274.     Else                                          'sub directory
  275.       If list1.List(0) = "[..]" Then              'we are not at root dir
  276.         Dir1.path = Dir1.List((list1.Listindex) - 1)
  277.       Else                                         'oh yes we are
  278.         Dir1.path = Dir1.List(list1.Listindex)
  279.       End If
  280.       Dir1_change                                  'do the event
  281.     End If
  282.   End If
  283. Exit Sub
  284.  
  285. list1_error:                                        'uh oh!
  286.     
  287.     Beep
  288.     If Err = FILE_NOT_FOUND Then
  289.         Button = MB_OK + MB_ICONEXCLAMATION
  290.     Else
  291.         Button = MB_ICONQUESTION + MB_RETRYCANCEL
  292.     End If
  293.     Button = MsgBox("ERROR: " + Error$(Err) + Str$(Err), Button, "FILE OPEN")
  294.     If Button = IDRETRY Then
  295.       Resume
  296.     End If
  297.     On Error GoTo 0
  298.     Exit Sub
  299.     
  300. End Sub
  301.  
  302. Sub List1_Update ()
  303.  
  304.   ClearListBox list1
  305.   CurrDir = Dir1.path
  306.   
  307.   If Len(CurrDir) > 3 Then
  308.     list1.AddItem "[..]"
  309.     DirPos = Len(CurrDir) + 2
  310.   Else
  311.     DirPos = 4
  312.   End If
  313.  
  314.   For Count = 0 To Dir1.listcount - 1
  315.     list1.AddItem "[" + Mid$(Dir1.List(Count), DirPos